package com.aegean.CommercialHotelBookSystem.book.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.book.business.IBookBusiness;
import com.aegean.CommercialHotelBookSystem.book.businessImp.BookBusinessImpl;
import com.aegean.CommercialHotelBookSystem.factory.BusinessFactory;
import com.aegean.CommercialHotelBookSystem.factory.MyTools;
import com.aegean.CommercialHotelBookSystem.model.Book;

/**
 * Servlet implementation class BookManager
 */
public class BookManagerTide extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session=request.getSession();
		String book_Time = null;
		String hotel_Name = null;
		String user_Name = null;
		List<Book> books = null;
		String searchSelect = request.getParameter("searchSelect");
		String condition = MyTools.toGB2312(request.getParameter("condition"));
		if (searchSelect == null) {
		} else if (searchSelect.equals("book_Time")) {
			book_Time = condition;
		} else if (searchSelect.equals("hotel_Name")) {
			hotel_Name = condition;
		} else if (searchSelect.equals("user_Name")) {
			user_Name = condition;
		}
		IBookBusiness business = BusinessFactory.createBookBusiness();
		books = business.searchBooks(book_Time, hotel_Name, user_Name);
		if (books == null||books.isEmpty()) {
			books = new ArrayList<Book>();
		}
		int size = 12;
		int pagecount = (books.size() + size - 1) / size;
		session.setAttribute("Admin_Books", books);
		session.setAttribute("Admin_BooksPage", pagecount);
		request.getRequestDispatcher("Book_manage.action").forward(request,
				response);

	}

}
